package com.shop2cn.iapi.agentproducts.testcase;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.AddConditionRebateBean;
import com.shop2cn.iapi.agentproducts.parameter.rebate.ConditionRebateValueDto;
import com.shop2cn.iapi.agentproducts.service.AddConditionRebateCall;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.model.agentrebate.Ymt_ConditionRebate;
import com.ymttest.database.model.agentrebate.Ymt_ConditionRebateExample;
import com.ymttest.database.model.agentrebate.Ymt_ConditionRebateValue;
import com.ymttest.database.model.agentrebate.Ymt_ConditionRebateValueExample;
import com.ymttest.database.model.godmch.mch_depot_info;
/**
*添加返佣条件Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AddConditionRebate{
	private static AddConditionRebateBean addconditionrebateBean;
	private static AddConditionRebateCall addconditionrebateCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("添加返佣条件Test");
	}
	

	@Before
	public void caseUp() {
		addconditionrebateBean=new AddConditionRebateBean();
		addconditionrebateCall=new AddConditionRebateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addconditionrebateCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	/**
	 * 插入一条数据，验证两张表
	 * @param bean
	 */
	private void checkConditionRebate(AddConditionRebateBean bean,int rebateId){
		Ymt_ConditionRebateExample example2=new Ymt_ConditionRebateExample();
		example2.createCriteria()
		.andConditionRebateIdEqualTo(rebateId);
		Ymt_ConditionRebate ymt_ConditionRebate = SqlMapperFactory.getIntergratedProductMapper().selectYmtConditionRebateExample(example2).get(0);
		System.out.println(FormatUtil.beanToGSONString(ymt_ConditionRebate));
		Logger.verifyEquals(bean.getUserId(),ymt_ConditionRebate.getUserId(), "验证userid");
		Logger.verifyEquals(bean.getBrandIddatabase(),ymt_ConditionRebate.getBrandIdList(), "验证brandid");
		Logger.verifyEquals(bean.getFirstCategoryIddatabase(),ymt_ConditionRebate.getFirstCategoryIdList(), "验证FirstCategoryId");
		Logger.verifyEquals(bean.getDepotIddatabase(),ymt_ConditionRebate.getDepotIdList(), "验证DepotId");
		//验证ConditionType  根据设置的条件，会有不同的优先级
		int brands = bean.getBrandIdList()==null?0:bean.getBrandIdList().size()==0?0:1;//品牌
		int firsts = bean.getFirstCategoryIdList()==null?0:bean.getFirstCategoryIdList().size()==0?0:1;//品类
		int depots = bean.getDepotIdList()==null?0:bean.getDepotIdList().size()==0?0:1;//分仓
		int ConditionType = 0;
		
//		ConditionType = brands!=0?firsts!=0?depots!=0?1:2:depots!=0?6:5:firsts!=0?depots!=0?4:6:depots!=0?7:0;
		
		if(brands!=0&&firsts!=0&&depots!=0){
			ConditionType=1;
		}else if (brands!=0&&firsts!=0&&depots==0) {
			ConditionType=2;
		}else if (brands!=0&&firsts==0&&depots!=0) {
			ConditionType=3;
		}else if (brands==0&&firsts!=0&&depots!=0) {
			ConditionType=4;
		}else if (brands!=0&&firsts==0&&depots==0) {
			ConditionType=5;
		}else if (brands==0&&firsts!=0&&depots==0) {
			ConditionType=6;
		}else if (brands==0&&firsts==0&&depots!=0) {
			ConditionType=7;
		}else {
			ConditionType=0;
		}
		
		Logger.verifyEquals(ConditionType,ymt_ConditionRebate.getConditionType() ,"验证ConditionType"+brands+firsts+depots);
		Logger.verifyEquals(0,ymt_ConditionRebate.getAction(), "验证action");
		Logger.verifyEquals(rebateId,ymt_ConditionRebate.getConditionRebateId(), "验证action");
		bean.getCatalogRebateList().forEach(b->{
			Ymt_ConditionRebateValueExample example3=new Ymt_ConditionRebateValueExample();
			example3.createCriteria()
			.andAgentTypeIdEqualTo(b.getAgentTypeId())
			.andConditionRebateIdEqualTo(rebateId);
			Ymt_ConditionRebateValue ymt_ConditionRebateValue = SqlMapperFactory.getIntergratedProductMapper().selectYmtConditionRebateValueExample(example3).get(0);
			Logger.verifyEquals(rebateId, ymt_ConditionRebateValue.getConditionRebateId(),"验证ConditionRebateId");
			Logger.verifyEquals(b.getAgentTypeId(),ymt_ConditionRebateValue.getAgentTypeId(), "验证AgentTypeId");
			Logger.verifyEquals(b.getRebateValue().doubleValue(),ymt_ConditionRebateValue.getRebateValue().doubleValue(), "验证RebateValue");
			Logger.verifyEquals(ymt_ConditionRebateValue.getRebateType(),1, "验证RebateType");
			Logger.verifyEquals(ymt_ConditionRebateValue.getAction(),0, "验证RebateType");
		});
		
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_001() {
		Logger.start(true,"三个条件分别设置，两个下级代理有10，30的佣金佣金");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			createDepotBean bean=GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1001));
			addconditionrebateBean.setDepotIdList(Arrays.asList(addAgentProductBean.getDepotId()));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_002() {
		Logger.start(true,"设置品牌品类，验证不同代理类型和不同佣金");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1001));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_003() {
		Logger.start(true,"设置品牌和分仓，两个下级代理有10，30的佣金佣金");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			createDepotBean bean=GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			addconditionrebateBean.setDepotIdList(Arrays.asList(addAgentProductBean.getDepotId()));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_004() {
		Logger.start(true,"设置品类和分仓，两个下级代理有10，30的佣金佣金");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			createDepotBean bean=GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1001));
			addconditionrebateBean.setDepotIdList(Arrays.asList(addAgentProductBean.getDepotId()));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_005() {
		Logger.start(true,"设置品牌，两个下级代理有10，30的佣金佣金");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_006() {
		Logger.start(true,"设置品类，两个下级代理有10，30的佣金佣金");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1001));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
		
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_007() {
		Logger.start(true,"设置分仓，两个下级代理有10，30的佣金佣金");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			createDepotBean bean=GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean, 7);
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_008() {
		Logger.start(true,"添加多条策略优先级一致的，失败");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			createDepotBean bean=GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1001));
			addconditionrebateBean.setDepotIdList(Arrays.asList(addAgentProductBean.getDepotId()));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();				
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			addconditionrebateCall.callService();
			Logger.verifyEquals("201", addconditionrebateCall.getString("code"), "验证code");
			Logger.verifyIsContains("已存在相同策略优先级", addconditionrebateCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_009() {
		Logger.start(true,"catalogRebateList为空失败");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			createDepotBean bean=GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1001));
			addconditionrebateBean.setDepotIdList(Arrays.asList(addAgentProductBean.getDepotId()));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();				
			Logger.verifyEquals("400", addconditionrebateCall.getString("code"), "验证code");
			Logger.verifyEquals("catalogRebateList:may not be empty", addconditionrebateCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0010() {
		Logger.start(true,"添加多条策略级不同的条件");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			createDepotBean bean=GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean.setUserId(userId);
			addconditionrebateBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1001));
			addconditionrebateBean.setDepotIdList(Arrays.asList(addAgentProductBean.getDepotId()));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();						
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setDepotIdList(null);
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();						
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setFirstCategoryIdList(null);
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();						
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setBrandIdList(null);
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1001));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();						
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setDepotIdList(Arrays.asList(addAgentProductBean.getDepotId()));
			addconditionrebateBean.setCatalogRebateList(Arrays.asList(new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentTypeId(),new BigDecimal(10)),new ConditionRebateValueDto(addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(1).getAgentTypeId(),new BigDecimal(30))));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();						
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0011() {
		Logger.start(true,"添加多条策略级不同的条件");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			createDepotBean bean=GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			for (int i = 1; i < 8; i++) {
				Thread.sleep(1000);
				addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean, i);
				addconditionrebateCall.setData(addconditionrebateBean);
				addconditionrebateCall.callService();						
				Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
				checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0012() {
		Logger.start(true,"两个不同的仓库，没有重复，成功");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			GodmchManageCallService.createDepot(userId);
			GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByMchIdAndSuccess(userId);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean,1);
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setDepotIdList(Arrays.asList(selectDepotByDepotTitle.get(1).getDepotId()));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0013() {
		Logger.start(true,"两条类型1，仓库不同 没有重复，成功");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			GodmchManageCallService.createDepot(userId);
			GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByMchIdAndSuccess(userId);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean,1);
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setDepotIdList(Arrays.asList(selectDepotByDepotTitle.get(1).getDepotId()));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0014() {
		Logger.start(true,"两个类型1，品牌不重复，成功");
		try {
			//创建一个商户和分销小店
			Integer userId = GodmchManageCallService.CreateGodMch();
			Integer StoreId = GodmchManageCallService.CreateStores(userId, 20);
			
			GodmchManageCallService.createDepot(userId);
			GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByMchIdAndSuccess(userId);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean,1);
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			addconditionrebateBean.getCatalogRebateList().get(0).setRebateValue(new BigDecimal(30));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("201", addconditionrebateCall.getString("code"), "验证code");
//			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0016() {
		Logger.start(true,"两个类型1，品类不重复，成功");
		try {
			//创建一个商户和分销小店
			Integer userId = GodmchManageCallService.CreateGodMch();
			Integer StoreId = GodmchManageCallService.CreateStores(userId, 20);
			
			GodmchManageCallService.createDepot(userId);
			GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByMchIdAndSuccess(userId);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean,1);
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(1,2));
			addconditionrebateBean.getCatalogRebateList().get(0).setRebateValue(new BigDecimal(30));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0017() {
		Logger.start(true,"第一条，品牌1,2，分类3,4，仓库5,6   第二条，品牌7,8,1，分类3,5，仓库6,7   品牌有重复，失败");
		try {
			//创建一个商户和分销小店
			Integer userId = GodmchManageCallService.CreateGodMch();
			Integer StoreId = GodmchManageCallService.CreateStores(userId, 20);
			
			GodmchManageCallService.createDepot(userId);
			GodmchManageCallService.createDepot(userId);
			GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByMchIdAndSuccess(userId);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			
			addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean, 1);
			addconditionrebateBean.setBrandIdList(Arrays.asList(1,2));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(3,4));
			addconditionrebateBean.setDepotIdList(Arrays.asList(5,6));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setBrandIdList(Arrays.asList(7,8,1));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(3,5));
			addconditionrebateBean.setDepotIdList(Arrays.asList(6,7));
			addconditionrebateBean.getCatalogRebateList().get(0).setRebateValue(new BigDecimal(30));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("201", addconditionrebateCall.getString("code"), "验证code");
//			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0018() {
		Logger.start(true,"第一条，品牌1,2，分类3,4，仓库5,6   第二条，品牌1,2，分类3,5，仓库6,7   品类有重复，失败");
		try {
			//创建一个商户和分销小店
			Integer userId = GodmchManageCallService.CreateGodMch();
			Integer StoreId = GodmchManageCallService.CreateStores(userId, 20);
			
			GodmchManageCallService.createDepot(userId);
			GodmchManageCallService.createDepot(userId);
			GodmchManageCallService.createDepot(userId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByMchIdAndSuccess(userId);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			
			addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean, 1);
			addconditionrebateBean.setBrandIdList(Arrays.asList(1,2));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(3,4));
			addconditionrebateBean.setDepotIdList(Arrays.asList(5,6));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setBrandIdList(Arrays.asList(1,2));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(3,5));
			addconditionrebateBean.setDepotIdList(Arrays.asList(6,7));
			addconditionrebateBean.getCatalogRebateList().get(0).setRebateValue(new BigDecimal(30));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("201", addconditionrebateCall.getString("code"), "验证code");
//			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddConditionRebate_0019() {
		Logger.start(true,"第一条，品牌1,2，分类3,4   第二条，品牌1,2，分类3,5  品类有重复，失败");
		try {
			//创建一个商户和分销小店
			Integer userId = GodmchManageCallService.CreateGodMch();
			
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByMchIdAndSuccess(userId);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			
			
			addconditionrebateBean=AddAgentProductCallService.InitAddCondictionRebate(addAgentProductBean, 1);
			addconditionrebateBean.setBrandIdList(Arrays.asList(1));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(2));
			addconditionrebateBean.setDepotIdList(null);
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("200", addconditionrebateCall.getString("code"), "验证code");
			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
			
			
			addconditionrebateBean.setBrandIdList(Arrays.asList(1));
			addconditionrebateBean.setFirstCategoryIdList(Arrays.asList(2,2));
			addconditionrebateBean.getCatalogRebateList().get(0).setRebateValue(new BigDecimal(30));
			addconditionrebateCall.setData(addconditionrebateBean);
			addconditionrebateCall.callService();			
			Logger.verifyEquals("201", addconditionrebateCall.getString("code"), "验证code");
//			checkConditionRebate(addconditionrebateBean,addconditionrebateCall.getRebateId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	
	
	
}